<?php

	/**
	 * Workspace@ Engine application comment!
	 * 
	 * LICENSE
	 * This application is licensed under New BSD license.
	 * Please read complete LICENSE.txt inside of root folder for more details.
	 * 
	 * We wish you good building :) 
	 * 
	 * @category   Application
	 * @package    Bootstrap
	 * @author     Nevio Vesic <nevio@workspaceat.com>
	 * @copyright  2008-2009 Workspace@ group in association with Design strategist
	 */

	class Engine_Plugins extends Engine_Application_Configuration 
	{
		/**
		 * Current object instance
		 *
		 * @var Object[this]
		 */
		protected static $instance = null;
		
		/**
		 * Plugins class prefix
		 */
		const CLASS_PREFIX  = "Engine_Plugins_";
		
		/**
		 * PHP file extension
		 */
		const FILENAME_EXT  = ".php";
		
		protected static $djubre = null;
		/**
		 * Create instance
		 *
		 * @return Object[self]
		 */
		public static function getInstance( $data )
		{
			if ( self::$djubre )
			{
				self::$djubre = null;
			}
			
			self::$djubre = $data;
			
			if (! self::$instance )
				self::$instance = new self ( $data );
				
			return self::$instance;
		}
		
		public function __get( $name )
		{
			$name = ucfirst( $name );
			
			if (! @fopen ( "Plugins/" . $name . self::FILENAME_EXT, "r", true ) )
			{
				throw new Engine_Exception( "{$name} plugin can't be allocated! Please recheck your instalation!" );
			}
			
			require_once "Plugins/" . $name . self::FILENAME_EXT;
			
			$class = self::CLASS_PREFIX . $name;
			if (! class_exists( $class ) )
			{
				throw new Engine_Exception( "{$name} plugin class can't be allocated! Please recheck your instalation!" );
			}
			
			return new $class( self::$djubre );
		}
	}

